#ifndef OPT_H
#define OPT_H
#include <stdio.h>

enum option_type {
	OPT_FLAG,
	OPT_NUMBER,
	OPT_TIME,
	OPT_STRING,
	OPT_FUNC,
	OPT_GROUP,
	OPT_END,
} type;

struct option_group;
struct option_def {
	enum option_type type;
	char shortname;
	const char *longname;
	union {
		int *flag;
		unsigned long *number;
		long *time;
		const char **string;
		int (*func)(const struct option_def *, const char *);
		const struct option_group *group;
	} ptr;
	const char *help;
	const char *argname;
};

struct option_group {
	const char *name;
	const char *description;
	const struct option_def *defs;
};

int parse_options(int argc, const char *const *argv,
			const struct option_group *og,
			int noptc, const char **noptv);
void print_options(const struct option_group *og);
FILE *open_file(const char *name, char mode);
void close_file(FILE *f);
FILE *open_tmpfile(const char *name, char mode);
void remove_tmp(const char *name);
void replace_tmp(const char *name);
#endif /* OPT_H */

